home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_4 / tch.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  501 b   |  25 lines  |  [MATF/MATL]

  1. function p = tch(C,n,x,a,b)
  2. % p = tch(C,n,x)
  3. % p = tch(C,n,x,a,b)
  4. % C is the coefficient list, input.
  5. % n is the degree, input.
  6. % x are the value(s), input.
  7. % a is the left  endpoint, input.
  8. % b is the right endpoint, input.
  9. % p are the function value(s), output.
  10. if nargin==3, a=-1; b=1; end
  11. x = 2*(x-a)/(b-a) - 1;
  12. T0 = ones(1,length(x));
  13. p = C(1)*T0;
  14. if n==0, return, end
  15. T1 = x;
  16. p = p + C(2)*T1;
  17. if n==1, return, end
  18. for j=3:n+1,
  19.   Tj = 2*x.*T1 - T0;
  20.   p  = p + C(j)*Tj;
  21.   T0 = T1;
  22.   T1 = Tj;
  23. end
  24.  
  25.